<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

class CreateProductSpecsTable extends Migration
{
    /**
     * SKU：商品规格库存表
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('product_specs')) {
            Schema::create('product_specs', function (Blueprint $table) {
                $table->id();
                $table->integer('product_id')->comment('商品ID:product_bases.id');
                $table->string('spec_attrid')->nullable()->comment('规格属性 ID 组合,如:1,4,5为对应1,4,5的规格属性组合,空为主商品');
                $table->string('title')->comment('商品规格标题');
                $table->string('subtitle')->nullable()->comment('商品规格副标题');
                $table->string('cover_img')->nullable()->comment('商品规格封面图');
                $table->string('gallery_img')->nullable()->comment('商品规格相册');
                $table->integer('price')->default(0)->comment('规格商品基础单价,单位为:分');
                $table->integer('weight')->default(0)->comment('商品规格重量,单位为:克');
                $table->integer('stock')->default(0)->comment('商品规格库存');
                $table->integer('order')->default(0)->comment('排序');
                $table->enum('status', ['normal', 'nosale'])->default('normal')->comment('商品规格状态:normal上架 / nosale下架');
                $table->softDeletes();
                $table->timestamps();
            });
            DB::statement("ALTER TABLE `product_specs` comment '商品规格表'");
        }
        // INSERT INTO `release_apis`.`product_specs` (`id`, `product_id`, `spec_attrid`, `title`, `subtitle`, `cover_img`, `gallery_img`, `price`, `stock`, `weight`, `remark`, `status`, `deleted_at`, `created_at`, `updated_at`) VALUES ('86', '85', '227,229', '绿冰', '绿豆', '143', NULL, '5000000', '1', '10000000', NULL, 'normal', NULL, '2023-11-29 11:25:13', '2023-11-29 11:25:13');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('product_specs');
    }
}
